﻿Namespace UserInterface
    Public Class dbiWSFReporting

#Region "**Classes**"
        Public Class dbiWSFReportObject

#Region "**Local Variables**"
            Private l_dbiWSFObject As dbiWSF.FrameworkObjects.objWSFObjects
            Private l_ReportName As String
            Private l_ReportTitle As String
            Private l_DateRange As String
            Private l_Criteria As String
            Private l_ReportColumns As New Collections.Generic.List(Of Dbi.WinControl.dbiColumnItem)
            Private l_ReportLines As New Dbi.WinControl.NodeItemCollection
            Private l_ColumnDelimiter As Char = ";"
            Private l_ListType As Dbi.WinControl.enumListType
            Private l_BodyIndent As Integer
            Private startDate As DateTime = Today
            Private endDate As DateTime = Today.AddDays(7)
#End Region

#Region "**Public Properties**"

            ''' <summary>
            ''' The name of the report.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The name of the report.")> _
                Public Property reportName() As String
                Get
                    Return l_ReportName
                End Get
                Set(ByVal value As String)
                    l_ReportName = value
                End Set
            End Property

            ''' <summary>
            ''' The main dbiWSFObjects for the project.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The main dbiWSFObjects for the project.")> _
            Public Property reportWSFObject() As dbiWSF.FrameworkObjects.objWSFObjects
                Get
                    Return l_dbiWSFObject
                End Get
                Set(ByVal value As dbiWSF.FrameworkObjects.objWSFObjects)
                    l_dbiWSFObject = value
                End Set
            End Property

            ''' <summary>
            ''' The start date of the report.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The start date of the report.")> _
            Public Property reportStart() As DateTime
                Get
                    Return startDate
                End Get
                Set(ByVal value As DateTime)
                    startDate = value
                End Set
            End Property

            ''' <summary>
            ''' The end date of the report.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The end date of the report.")> _
            Public Property reportEnd() As DateTime
                Get
                    Return endDate
                End Get
                Set(ByVal value As DateTime)
                    endDate = value
                End Set
            End Property

            ''' <summary>
            ''' The report title text.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The report title text.")> _
            Public Property ReportTitle() As String
                Get
                    Return l_ReportTitle
                End Get
                Set(ByVal value As String)
                    l_ReportTitle = value
                End Set
            End Property

            ''' <summary>
            ''' The date range text for the report.
            ''' </summary>
            ''' <remarks>This is a string for display only the actual start and end dates
            ''' are separate properties.</remarks>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The date range text for the report.")> _
            Public Property DateRange() As String
                Get
                    Return l_DateRange
                End Get
                Set(ByVal value As String)
                    l_DateRange = value
                End Set
            End Property

            ''' <summary>
            ''' The criteria text to display.
            ''' </summary>
            ''' <remarks>This is a string field for printing, it is not used for actual report criteria.
            ''' That is determined by the Sub generateReport.</remarks>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The criteria text to display.")> _
            Public Property Criteria() As String
                Get
                    Return l_Criteria
                End Get
                Set(ByVal value As String)
                    l_Criteria = value
                End Set
            End Property

            ''' <summary>
            ''' A collection of dbi.WinControl.dbiColumnItems to use in the dbiList1.
            ''' </summary>
            ''' <remarks>These columns are used to specify display types and formatting for the dbiList1.</remarks>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("A collection of dbi.WinControl.dbiColumnItems to use in the dbiList1.")> _
            Public Property ReportColumns() As Collections.Generic.List(Of Dbi.WinControl.dbiColumnItem)
                Get
                    Return l_ReportColumns
                End Get
                Set(ByVal value As Collections.Generic.List(Of Dbi.WinControl.dbiColumnItem))
                    l_ReportColumns = value
                End Set
            End Property

            ''' <summary>
            ''' A dbi.WinControl.NodeItemCollection that represents the actual lines of the report.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description(" A dbi.WinControl.NodeItemCollection that represents the actual lines of the report.")> _
            Public Property ReportLines() As Dbi.WinControl.NodeItemCollection
                Get
                    Return l_ReportLines
                End Get
                Set(ByVal value As Dbi.WinControl.NodeItemCollection)
                    l_ReportLines = value
                End Set
            End Property

            ''' <summary>
            ''' The character used to delimit the column information in the nodes of the ReportLines.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("The character used to delimit the column information in the nodes of the ReportLines.")> _
            Public Property ColumnDelimiter() As Char
                Get
                    Return l_ColumnDelimiter
                End Get
                Set(ByVal value As Char)
                    l_ColumnDelimiter = value
                End Set
            End Property

            ''' <summary>
            ''' Determines the type of dbiList to display.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("Determines the type of dbiList to display.")> _
            Public Property ReportListType() As Dbi.WinControl.enumListType
                Get
                    Return l_ListType
                End Get
                Set(ByVal value As Dbi.WinControl.enumListType)
                    l_ListType = value
                End Set
            End Property


            ''' <summary>
            ''' Determines the horizontal indent of the body text in relation to the node text in dbiList1.
            ''' </summary>
            <System.ComponentModel.Category("dbiWSF Reports"), _
            System.ComponentModel.Description("Determines the horizontal indent of the body text in relation to the node text in dbiList1.")> _
            Public Property BodyIndent() As Integer
                Get
                    Return l_BodyIndent
                End Get
                Set(ByVal value As Integer)
                    l_BodyIndent = value
                End Set
            End Property
#End Region

#Region "**dbiWSFReportObject Methods**"
            Public Sub New(ByRef wsfObject As dbiWSF.FrameworkObjects.objWSFObjects)
                'Set the dbiWSFObject
                l_dbiWSFObject = wsfObject

            End Sub

            Public Sub AddColumn(ByVal columnText As String, ByVal columnWidth As Integer, ByVal columnType As Dbi.WinControl.enumDataType, Optional ByVal headerAlignment As Dbi.WinControl.enumAlignment = Dbi.WinControl.enumAlignment.Default, Optional ByVal columnAlignment As Dbi.WinControl.enumAlignment = Dbi.WinControl.enumAlignment.Default)
                'Add a new column to the report definition
                Dim column2Add As New Dbi.WinControl.dbiColumnItem(columnText, columnWidth)

                column2Add.DataType = columnType
                column2Add.TextAlign = headerAlignment
                column2Add.Format.TextAlign = columnAlignment
                l_ReportColumns.Add(column2Add)

            End Sub

            Public Sub ResetReport()
                'Clear out the report lines prior to regenerating the report
                l_ReportLines.Clear()
                l_ReportColumns.Clear()
            End Sub
#End Region

        End Class
#End Region

#Region "**Report Templates and Classes**"

#Region "##Report Template##"
        'Public Class reportTemplate
        '    Inherits dbiReportOjbect     'All reports must inherit from the report object
        '    Public Sub New(ByRef wsfObject As dbiWSF.FrameworkObjects.objWSFObjects)   'All reports must set the dbiWSFObject to get a handle to the data
        '        MyBase.New(wsfObject)
        '        Me.reportName = 
        '    End Sub

        ''Report Layout
        '

        '    Public Sub generateReport()
        '     'Specific Code for generating report
        '       Me.ReportTitle = "Daily Shipments by Warehouse Report"
        '       Me.DateRange = Me.reportStart.ToLongDateString '& " to " & Me.reportEnd.ToLongDateString
        '       Me.ColumnDelimiter = ";"
        '       Me.ReportListType = Dbi.WinControl.enumListType.ListView
        '       'Add the columns for the items in the report

        '    End Sub

        'End Class
#End Region
        ''' <summary>Daily Shipments by Warehouse Report</summary>
        Public Class reportDailyShipmentsByWarehouse
            Inherits dbiWSFReportObject     'All reports must inherit from the report object
            Public Sub New(ByRef wsfObject As dbiWSF.FrameworkObjects.objWSFObjects)   'All reports must set the dbiWSFObject to get a handle to the data
                MyBase.New(wsfObject)
                Me.reportName = "DailyShipmentsByWarehouse"
            End Sub

            'Report Layout
            'Warehouse Description
            '   Loading Dock Description
            '       Carrier                     Time In     Time Out    Inbound/Outbound
            '       Order Entry Type: Order Entry ID
            '       Cargo Type - Quantity

            Public Sub generateReport()
                Dim warehouseFont As New System.Drawing.Font("Calibri", 11, Drawing.FontStyle.Bold)
                Dim loadingDockFont As New System.Drawing.Font("Calibri", 9, Drawing.FontStyle.Bold)
                Me.ReportTitle = "Daily Shipments by Warehouse Report"
                Me.DateRange = Me.reportStart.ToLongDateString '& " to " & Me.reportEnd.ToLongDateString
                Me.ColumnDelimiter = ";"
                Me.ReportListType = Dbi.WinControl.enumListType.ListView
                Me.BodyIndent = 50

                'Add a column at the front of the report to force a margin
                Dim marginColumn As New Dbi.WinControl.dbiColumnItem
                marginColumn.Width = 50
                marginColumn.LockWidth = True
                marginColumn.Text = "     "

                Me.ReportColumns.Add(marginColumn)

                'Add the remaining columns for the items in the report
                Me.AddColumn("Carrier", 200, Dbi.WinControl.enumDataType.Text, Dbi.WinControl.enumAlignment.MiddleLeft)
                Me.AddColumn("Time In", 120, Dbi.WinControl.enumDataType.Text, , Dbi.WinControl.enumAlignment.MiddleLeft)
                Me.AddColumn("Time Out", 120, Dbi.WinControl.enumDataType.Text, , Dbi.WinControl.enumAlignment.MiddleLeft)
                Me.AddColumn("Inbound/Outbound", 120, Dbi.WinControl.enumDataType.Text, Dbi.WinControl.enumAlignment.MiddleLeft)

                Dim warehouseObject As dbiWSF.FrameworkObjects.objWarehouse

                For Each warehouseObject In Me.reportWSFObject.Warehouses

                    'Add a warehouse description as a header item
                    Dim warehouseDesc As New Dbi.WinControl.dbiNodeItem
                    warehouseDesc.Text = warehouseObject.Description
                    warehouseDesc.Header = True
                    warehouseDesc.Font = warehouseFont
                    warehouseDesc.ForeColor = Drawing.Color.White
                    warehouseDesc.BackColor = Drawing.Color.Gray

                    warehouseDesc.Tag = warehouseObject

                    Me.ReportLines.Add(warehouseDesc)

                    Dim loadingDockLinq = From LoadingDocks As dbiWSF.FrameworkObjects.objLoadingDock In warehouseObject.LoadingDocks _
                                          Order By LoadingDocks.WarehouseOrdinal _
                                          Select LoadingDocks

                    For Each loadingDock As dbiWSF.FrameworkObjects.objLoadingDock In loadingDockLinq

                        'Add a warehouse description as a header item
                        Dim loadingdockDesc As New Dbi.WinControl.dbiNodeItem
                        loadingdockDesc.Text = "     " + loadingDock.Description
                        loadingdockDesc.Header = True
                        loadingdockDesc.Font = loadingDockFont
                        loadingdockDesc.ForeColor = Drawing.Color.Black
                        loadingdockDesc.BackColor = Drawing.Color.LightGray

                        loadingdockDesc.Tag = loadingDock

                        Me.ReportLines.Add(loadingdockDesc)

                        Dim shipmentsLinq = From Shipments As dbiWSF.FrameworkObjects.objShipment In loadingDock.Shipments _
                                            Where Shipments.SchedStartTime.Date = reportStart _
                                            Order By Shipments.SchedStartTime _
                                            Select Shipments

                        For Each shipment As dbiWSF.FrameworkObjects.objShipment In shipmentsLinq

                            'Add a report line for the shipment
                            Dim shipmentDetail As New Dbi.WinControl.dbiNodeItem

                            '****************** Point of Integration ******************
                            'The Carrier file is not part of the dbiWSF and therefore requires a call to an external Carrier Table to return the Carrier Name, etc.
                            shipmentDetail.Text = Me.ColumnDelimiter + _
                                                  "Carrier (ID: " + shipment.CarrierID.Trim + ")" + Me.ColumnDelimiter + _
                                                  shipment.SchedStartTime.ToShortTimeString + Me.ColumnDelimiter + _
                                                  shipment.SchedEndTime.ToShortTimeString + Me.ColumnDelimiter + _
                                                  shipment.ShipmentType.ToString

                            shipmentDetail.Tag = shipment

                            'Get the shipment details

                            For Each orderHeader As dbiWSF.FrameworkObjects.objOrderHeader In shipment.OrderHeaders

                                'Add one line to the body for the order header
                                shipmentDetail.Body = orderHeader.OrderEntryType + ":" + orderHeader.OrderEntryID + vbCrLf
                                '****************** Point of Integration ******************
                                'The Invoicing/PO/Transfer Processing files are not part of the dbiWSF.  
                                'Accordingly the Item Description will come from an external table
                                For Each orderDetail As dbiWSF.FrameworkObjects.objOrderDetail In orderHeader.OrderDetails

                                    'Add one line to the body for each order detail
                                    shipmentDetail.Body = shipmentDetail.Body + _
                                                          Me.reportWSFObject.GetCargoDescripFromID(orderDetail.CargoTypeID) + "/" + _
                                                          " Item Description" + _
                                                          " Qty: " + orderDetail.Quantity.ToString + _
                                                          " Weight: " + orderDetail.UnitWeight + " " + orderDetail.UnitOfMeasure + _
                                                          " Total: " + (orderDetail.Quantity * Val(orderDetail.UnitWeight)).ToString + " " + orderDetail.UnitOfMeasure

                                    shipmentDetail.Body = shipmentDetail.Body + vbCrLf

                                Next

                                shipmentDetail.BodyVisible = True

                            Next

                            Me.ReportLines.Add(shipmentDetail)

                        Next    'Shipment

                    Next    'Loading Dock

                Next    'Warehouse

            End Sub

        End Class
        ''' <summary>Daily Sign-In Sheet</summary>
        Public Class reportDailySignInSheet
            Inherits dbiWSFReportObject     'All reports must inherit from the report object
            Public Sub New(ByRef wsfObject As dbiWSF.FrameworkObjects.objWSFObjects)   'All reports must set the dbiWSFObject to get a handle to the data
                MyBase.New(wsfObject)
                Me.reportName = "reportDailySignInSheet"
            End Sub

            'Report Layout
            'For Warehouse:                 On: DDDD MMMM dd, YYYY        
            'Loading Dock    Carrier        Scheduled In        Scheduled Out       Time In     Time Out

            Public Sub generateReport()
                'NOTE: The WarehouseID is passed on the Me.Criteria property

                Dim blankColumn As New String("_", 12)

                Me.ReportTitle = "Daily Sign In Sheet"
                Me.DateRange = Me.reportStart.ToLongDateString
                Me.ColumnDelimiter = ";"
                Me.ReportListType = Dbi.WinControl.enumListType.ListView

                Me.AddColumn("Scheduled In", 80, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Scheduled Out", 90, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Carrier", 175, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Loading Dock", 150, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Time In", 100, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Time Out", 100, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Logged By", 100, Dbi.WinControl.enumDataType.Text)

                'Get the warehouse object from the dbiWSF object
                Dim warehouse2Process As dbiWSF.FrameworkObjects.objWarehouse
                warehouse2Process = reportWSFObject.GetWarehouseFromGUID(New Guid(Me.Criteria))

                Dim shipmentsLinq = From loadingdocks As dbiWSF.FrameworkObjects.objLoadingDock In warehouse2Process.LoadingDocks _
                                        From Shipments As dbiWSF.FrameworkObjects.objShipment In loadingdocks.Shipments _
                                        Where Shipments.SchedStartTime.Date = Me.reportStart _
                                        Order By Shipments.SchedStartTime _
                                        Select Shipments

                Dim shipment2Process As dbiWSF.FrameworkObjects.objShipment

                For Each shipment2Process In shipmentsLinq
                    Dim reportLine As New Dbi.WinControl.dbiNodeItem

                    reportLine.Text = shipment2Process.SchedStartTime.ToShortTimeString + Me.ColumnDelimiter + _
                                      shipment2Process.SchedEndTime.ToShortTimeString + Me.ColumnDelimiter + _
                                      "Carrier (" + shipment2Process.CarrierID + ")" + Me.ColumnDelimiter + _
                                      reportWSFObject.GetLoadingDockFromGUID(shipment2Process.LoadingDockID).Description + Me.ColumnDelimiter + _
                                      blankColumn + Me.ColumnDelimiter + blankColumn + Me.ColumnDelimiter + blankColumn

                    Me.ReportLines.Add(reportLine)

                Next    'shipment2Process

                Me.Criteria = warehouse2Process.Description

            End Sub

        End Class
        ''' <summary>Projected Inbound Shipments Report</summary>
        Public Class reportProjectedInboundShipments
            Inherits dbiWSFReportObject     'All reports must inherit from the report object
            Public Sub New(ByRef wsfObject As dbiWSF.FrameworkObjects.objWSFObjects)   'All reports must set the dbiWSFObject to get a handle to the data
                MyBase.New(wsfObject)
                Me.reportName = "reportProjectedInboundShipments"
            End Sub

            Public totalsFont As New System.Drawing.Font("Calibri", 11, Drawing.FontStyle.Bold)

            'Report Layout
            'Projected Inbound Shipments for MMM dd, YYYY to MMM dd, YYYY
            'Scheduled In   Cargo Type  Warehouse  Item Description Quantity    Units   Weight  Total
            Private Class totalStructure
                Dim l_cargoTypeID As Guid
                Dim l_shipmentsCount As Long
                Dim l_totalQuantity As Double
                Dim l_totalWeight As Double
                Dim l_totalExtended As Double

                Property cargoTypeID() As Guid
                    Get
                        Return l_cargoTypeID
                    End Get
                    Set(ByVal value As Guid)
                        l_cargoTypeID = value
                    End Set
                End Property

                Property shipmentsCount() As Long
                    Get
                        Return l_shipmentsCount
                    End Get
                    Set(ByVal value As Long)
                        l_shipmentsCount = value
                    End Set
                End Property
                Property totalQuantity() As Double
                    Get
                        Return l_totalQuantity
                    End Get
                    Set(ByVal value As Double)
                        l_totalQuantity = value
                    End Set
                End Property

                Property totalWeight() As Double
                    Get
                        Return l_totalWeight
                    End Get
                    Set(ByVal value As Double)
                        l_totalWeight = value
                    End Set
                End Property

                Property totalExtended() As Double
                    Get
                        Return l_totalExtended
                    End Get
                    Set(ByVal value As Double)
                        l_totalExtended = value
                    End Set
                End Property

                Public Sub New()
                    Me.shipmentsCount = 0
                    Me.totalQuantity = 0
                    Me.totalWeight = 0
                    Me.totalExtended = 0
                End Sub

            End Class

            Public Sub generateReport()
                'Specific Code for generating report
                Me.ReportTitle = "Projected Inbound Shipments"
                Me.DateRange = Me.reportStart.ToLongDateString + " to " & Me.reportEnd.ToLongDateString
                Me.ColumnDelimiter = ";"
                Me.ReportListType = Dbi.WinControl.enumListType.ListView
                'Add the columns for the items in the report
                Me.AddColumn("Scheduled In", 80, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Warehouse", 125, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Item Description", 125, Dbi.WinControl.enumDataType.Text)
                Me.AddColumn("Quantity", 80, Dbi.WinControl.enumDataType.Integer, Dbi.WinControl.enumAlignment.MiddleRight, Dbi.WinControl.enumAlignment.MiddleRight)
                Me.AddColumn("Unit of Measure", 120, Dbi.WinControl.enumDataType.Text, Dbi.WinControl.enumAlignment.MiddleCenter, Dbi.WinControl.enumAlignment.MiddleCenter)
                Me.AddColumn("Unit Weight", 80, Dbi.WinControl.enumDataType.Integer, Dbi.WinControl.enumAlignment.MiddleRight, Dbi.WinControl.enumAlignment.MiddleRight)
                Me.AddColumn("Total", 100, Dbi.WinControl.enumDataType.Integer, Dbi.WinControl.enumAlignment.MiddleRight, Dbi.WinControl.enumAlignment.MiddleRight)

                Dim orderDetailsLinq = From warehouses As dbiWSF.FrameworkObjects.objWarehouse In Me.reportWSFObject.Warehouses _
                                       From loadingdocks As dbiWSF.FrameworkObjects.objLoadingDock In warehouses.LoadingDocks _
                                       From shipments As dbiWSF.FrameworkObjects.objShipment In loadingdocks.Shipments _
                                       From orders As dbiWSF.FrameworkObjects.objOrderHeader In shipments.OrderHeaders _
                                       From orderdetails As dbiWSF.FrameworkObjects.objOrderDetail In orders.OrderDetails _
                                       Order By reportWSFObject.GetCargoDescripFromID(orderdetails.CargoTypeID), shipments.SchedStartTime.Date, warehouses.Description _
                                       Where shipments.SchedStartTime.Date >= Me.reportStart And shipments.SchedStartTime.Date <= Me.reportEnd _
                                       Select shipments.SchedStartTime, orderdetails.CargoTypeID, warehouses.Description, orderdetails.UnitOfMeasure, orderdetails.UnitWeight, orderdetails.Quantity

                Dim cargoTypeTotal As New totalStructure
                Dim reportTotal As New totalStructure

                For Each orderDetail2Process In orderDetailsLinq

                    If cargoTypeTotal.cargoTypeID = System.Guid.Empty Then

                        'Print out the first header
                        'Add a header report item for the new cargo type
                        Dim newCargoTypeLine As New Dbi.WinControl.dbiNodeItem
                        newCargoTypeLine.Text = Me.reportWSFObject.GetCargoDescripFromID(orderDetail2Process.CargoTypeID)
                        newCargoTypeLine.Header = True
                        newCargoTypeLine.Font = totalsFont

                        ReportLines.Add(newCargoTypeLine)

                        cargoTypeTotal.cargoTypeID = orderDetail2Process.CargoTypeID

                    Else

                        If Not orderDetail2Process.CargoTypeID.ToString = cargoTypeTotal.cargoTypeID.ToString Then

                            Dim totalLine As New Dbi.WinControl.dbiNodeItem
                            'Print out the total for the cargo type, add the cargo type totals to the report totals, and reset the cargo type accumulator
                            totalLine = printTotals(cargoTypeTotal, reportTotal)

                            ''Accumulate the cargo type totals to the report total
                            'reportTotal.shipmentsCount = reportTotal.shipmentsCount + cargoTypeTotal.shipmentsCount
                            'reportTotal.totalQuantity = reportTotal.totalQuantity + cargoTypeTotal.totalQuantity
                            'reportTotal.totalWeight = reportTotal.totalWeight + cargoTypeTotal.totalWeight
                            'reportTotal.totalExtended = reportTotal.totalExtended + cargoTypeTotal.totalExtended

                            ''zero out the total structure for the cargo type
                            'cargoTypeTotal.shipmentsCount = 0
                            'cargoTypeTotal.totalQuantity = 0
                            'cargoTypeTotal.totalWeight = 0
                            'cargoTypeTotal.totalExtended = 0

                            ReportLines.Add(totalLine)

                            'Add a header report item for the new cargo type
                            Dim newCargoTypeLine As New Dbi.WinControl.dbiNodeItem
                            newCargoTypeLine.Text = Me.reportWSFObject.GetCargoDescripFromID(orderDetail2Process.CargoTypeID)
                            newCargoTypeLine.Header = True
                            newCargoTypeLine.Font = totalsFont
                            newCargoTypeLine.PageBreak = True

                            ReportLines.Add(newCargoTypeLine)

                            'Set the new cargo type into the cargo type total structure
                            cargoTypeTotal.cargoTypeID = orderDetail2Process.CargoTypeID

                        End If

                    End If

                    'Process the current reportline
                    Dim reportLine As New Dbi.WinControl.dbiNodeItem

                    reportLine.Text = orderDetail2Process.SchedStartTime.ToShortDateString + Me.ColumnDelimiter + _
                                      orderDetail2Process.Description + Me.ColumnDelimiter + _
                                      "Item Description" + Me.ColumnDelimiter + _
                                      orderDetail2Process.Quantity.ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                      orderDetail2Process.UnitOfMeasure + Me.ColumnDelimiter + _
                                      CLng(orderDetail2Process.UnitWeight).ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                      (orderDetail2Process.Quantity * Val(orderDetail2Process.UnitWeight)).ToString("###,###,##0.##")

                    Me.ReportLines.Add(reportLine)

                    'Add the details values to the cargo type totals
                    cargoTypeTotal.shipmentsCount = cargoTypeTotal.shipmentsCount + 1
                    cargoTypeTotal.totalQuantity = cargoTypeTotal.totalQuantity + orderDetail2Process.Quantity
                    cargoTypeTotal.totalWeight = cargoTypeTotal.totalWeight + Val(orderDetail2Process.UnitWeight)
                    cargoTypeTotal.totalExtended = cargoTypeTotal.totalExtended + (orderDetail2Process.Quantity * Val(orderDetail2Process.UnitWeight))

                Next    'orderDetail2Process

                'Add the last cargo type total
                Dim lastTotalLine As New Dbi.WinControl.dbiNodeItem
                'Print out the total for the cargo type, add the cargo type totals to the report totals, and reset the cargo type accumulator
                lastTotalLine = printTotals(cargoTypeTotal, reportTotal)

                ReportLines.Add(lastTotalLine)

                'Add the total for the report
                Dim totalHeader As New Dbi.WinControl.dbiNodeItem

                totalHeader.Text = "Total For " + reportTotal.shipmentsCount.ToString.Trim + " shipments ..."
                totalHeader.Header = True
                totalHeader.Font = totalsFont
                totalHeader.PageBreak = True
                ReportLines.Add(totalHeader)

                Dim reportTotalLine As New Dbi.WinControl.dbiNodeItem
                'Print out the total for the cargo type, add the cargo type totals to the report totals, and reset the cargo type accumulator
                reportTotalLine.Text = (New String(Me.ColumnDelimiter, 3) + _
                                reportTotal.totalQuantity.ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                Me.ColumnDelimiter + _
                                CLng(reportTotal.totalWeight).ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                reportTotal.totalExtended.ToString("###,###,##0.##"))
                ReportLines.Add(reportTotalLine)


            End Sub

            Private Function printTotals(ByRef totals2Print As totalStructure, ByRef totals4Report As totalStructure) As Dbi.WinControl.dbiNodeItem
                Dim cargoTypeLine As New Dbi.WinControl.dbiNodeItem

                cargoTypeLine.Text = "Total For " + totals2Print.shipmentsCount.ToString.Trim + " " + Me.reportWSFObject.GetCargoDescripFromID(totals2Print.cargoTypeID) + " shipments ..."
                cargoTypeLine.Header = True
                cargoTypeLine.Font = totalsFont
                ReportLines.Add(cargoTypeLine)

                Dim totalLine As New Dbi.WinControl.dbiNodeItem
                totalLine.Text = (New String(Me.ColumnDelimiter, 3) + _
                                totals2Print.totalQuantity.ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                Me.ColumnDelimiter + _
                                CLng(totals2Print.totalWeight).ToString("###,###,##0.##") + Me.ColumnDelimiter + _
                                totals2Print.totalExtended.ToString("###,###,##0.##"))

                'Accumulate the cargo type totals to the report total
                totals4Report.shipmentsCount = totals4Report.shipmentsCount + totals2Print.shipmentsCount
                totals4Report.totalQuantity = totals4Report.totalQuantity + totals2Print.totalQuantity
                totals4Report.totalWeight = totals4Report.totalWeight + totals2Print.totalWeight
                totals4Report.totalExtended = totals4Report.totalExtended + totals2Print.totalExtended

                'zero out the total structure for the cargo type
                totals2Print.shipmentsCount = 0
                totals2Print.totalQuantity = 0
                totals2Print.totalWeight = 0
                totals2Print.totalExtended = 0

                printTotals = totalLine

            End Function

        End Class
#End Region

    End Class
End Namespace
